package com.lzx.service.jzny.impl;

import com.lzx.mapper.jzny.JznyMapper;
import com.lzx.model.jzny.Jzny;
import com.lzx.service.jzny.JznyService;
import com.lzx.utils.MethodUtil;
import com.lzx.utils.UuidUtil;
import com.sun.jndi.toolkit.url.UrlUtil;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("jznyService")
public class JznyServiceImpl implements JznyService {
    @Autowired
    JznyMapper jznyMapper;

    @Override
    public List<Jzny> findJznyAll(Jzny jzny) throws SQLException {
        return jznyMapper.findJznyAll(jzny);
    }

    @Override
    public List<Jzny> findJznyAllPage(Jzny jzny) throws SQLException {
        return jznyMapper.findJznyAllPage(jzny);
    }

    @Override
    public Jzny findJznyLast(Jzny jzny) throws SQLException {
        return jznyMapper.findJznyLast(jzny);
    }

    @Override
    public void insertshuju(String data,String userkey,String date) throws Exception {
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String,Object> map=new HashMap<String,Object>();
        String createTime= MethodUtil.formatDate(1,sdf.parse(date));
        String[] dataArr= data.split(",");
        map.put("id", UuidUtil.get32UUID());
        map.put("date",date );
        map.put("userkey", userkey);
        map.put("data", dataArr);
        map.put("time", createTime);

        List<Jzny> findByCreateTime = jznyMapper.findQxDataByCreateTime(map);
        if(findByCreateTime.size()==0){
            jznyMapper.addJzny(map);
        }

        System.out.println("完成");
    }
}
